﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.IsolatedStorage;
using System.IO;

namespace Ex7.IsolatedStorage
{
    class IsolatedStorage
    {
        static void Main(string[] args)
        {
            IsolatedStorageFile userStorage = IsolatedStorageFile.GetUserStoreForAssembly();
            using (userStorage)
            {
                IsolatedStorageFileStream stream =
                    new IsolatedStorageFileStream("example.txt", FileMode.OpenOrCreate, userStorage);
                using (stream)
                {
                    // Read the isolated storage file contents
                    TextReader reader = new StreamReader(stream);
                    string fileContents = reader.ReadToEnd();
                    Console.WriteLine("The program was last started on: {0}", fileContents);

                    // Modify the isolated storage file contents
                    stream.SetLength(0);
                    TextWriter writer = new StreamWriter(stream);
                    using (writer)
                    {
                        writer.Write(DateTime.Now);
                    }
                }
            }
        }
    }
}
